
<include file="Public/header"/><body>

<div class="tab_nav tab_nav_none">
    <div class="header">
	<a href="javascript:void(0);" onClick="javascript:history.go(-1);" class="header_l"><i class="fa fa-angle-left"></i></a>
      <div class="h-mid">信息修改   </div>
	<a href="{:U('Index/index')}" class="header_r"><i class="fa fa-home"></i></a>
	  
    </div>
</div>
<include file="Public/menu"/>
<div id="tbh5v0">
    <div class="Personal">
        <div id="tbh5v0">
            <div class="innercontent1">
                <form method="post" action="" id="edit_profile" onSubmit="return checkinfo()">
                    <div class="name"><span>昵　 稱</span>
                        <input type="text" name="nickname" id="nickname" value="{$user.nickname}" placeholder="*昵稱"
                               class="c-f-text">
                    </div>

                    <div class="name1"><span>性　 別</span>
                        <ul>
                            <li
                            <?php if($user['sex']==0) {echo 'class="on"';} ?>   >
                            <label for="sex0">
                                <input type="radio" name="sex" value="0" tabindex="2" class="radio"
                                       id="sex0" <?php if($user['sex']==0) {echo 'checked="checked"';} ?>>
                                保密</label>
                            </li>
                            <li
                            <?php if($user['sex']==1) {echo 'class="on"';} ?> >
                            <label for="sex1">
                                <input type="radio" name="sex" value="1" tabindex="3" class="radio"
                                       id="sex1" <?php if($user['sex']==1) {echo 'checked="checked"';} ?> >
                                男</label>
                            </li>
                            <li
                            <?php if($user['sex']==2) {echo 'class="on"';} ?> >
                            <label for="sex2">
                                <input type="radio" name="sex" value="2" tabindex="4" class="radio"
                                       id="sex2" <?php if($user['sex']==2) {echo 'checked="checked"';} ?>>
                                女</label>
                            </li>
                        </ul>
                    </div>
                    <div class="name">
                        <label for="email_ep"> <span>郵　 箱</span>
                            <input name="email" value="{$user.email}" id="email_ep" placeholder="*電子郵件地址" type="text"/>
                        </label>
                    </div>
                    <div class="field submit-btn">
                        <input type="submit" value="確認修改" class="btn_big1"/>
                    </div>
                </form>
            </div>

            <div class="innercontent1">
                <form method="post" action="" id="edit_mobile" onSubmit="return checkMobileForm()">
                    <div class="name">
                        <label for="email_ep"> <span>手機</span>
                            <input name="mobile" value="{$user.mobile}" id="mobile_ep" placeholder="*手機號碼" type="text"/>
                        </label>
                    </div>
                    <div class="name">
                        <label for="email_ep"> <span>驗證碼</span>
                            <input type="text" id="mobile_code"  name="mobile_code" placeholder="手機驗證碼" />
                            <input id="zphone" type="button" rel="mobile" value="獲取手機驗證碼" onClick="sendcode(this)"
                                   class="zphone">
                        </label>
                    </div>
                    <div class="field submit-btn">
                        <input type="submit" value="確認修改" class="btn_big1"/>
                    </div>
                </form>
            </div>

            <div class="innercontent1">
                <form name="formPassword" action="{:U('User/password')}" method="post" onSubmit="return editPassword()">

					 <div class="name"><span>原密碼</span>
                         <input type="password" name="old_password" id="password" class="c-f-text" placeholder="原密碼"  />
                    </div>
					
                     <div class="name">
                        <label for="email_ep">
						<span>新密碼</span>
                            <input type="password" name="new_password" id="new_password" placeholder="新密碼"  class="c-f-text"
                                  />
                        </label>
                    </div>
                     <div class="name">
                        <label for="email_ep">
						<span>確認密碼</span>
                            <input type="password" name="confirm_password" id="comfirm_password" placeholder="確認密碼" class="c-f-text"
                                  />
                        </label>
                    </div>
                    <div class="field submit-btn" style="padding-bottom:30px;">
                        <input type="submit" value="確認修改" class="btn_big1"/>
                    </div>
                </form>
            </div>
			
			
        </div>
    </div>

    <script>
        $('.name1 ul li').click(function () {
            $(this).find("input").attr("checked", "checked");
            $('.name1 ul li').removeClass("on");
            $(this).addClass("on");
        })
    </script>
</div>

<script language="javascript">
    $(function () {
        $('input[type=text],input[type=password]').bind({
            focus: function () {
                $(".global-nav").css("display", 'none');
            },
            blur: function () {
                $(".global-nav").css("display", 'flex');
            }
        });
    })

    var email_empty = "請輸入您的電子郵件地址！";
    var email_error = "您輸入的電子郵件地址格式不正確！";
    var old_password_empty = "請輸入您的原密碼！";
    var new_password_empty = "請輸入6位以上新密碼！";
    var confirm_password_empty = "請輸入6位以上確認密碼！";
    var both_password_error = "您現兩次輸入的密碼不壹致！";
    /* 會員修改密碼 */
    function editPassword() {
        var frm = document.forms['formPassword'];
        var old_password = frm.elements['old_password'].value;
        var new_password = frm.elements['new_password'].value;
        var confirm_password = frm.elements['comfirm_password'].value;

        var msg = '';
        var reg = null;

        if (old_password.length == 0) {
            msg += old_password_empty + '\n';
        }

        if (new_password.length < 6) {
            msg += new_password_empty + '\n';
        }

        if (confirm_password.length < 6) {
            msg += confirm_password_empty + '\n';
        }

        if (new_password.length > 0 && confirm_password.length > 0) {
            if (new_password != confirm_password) {
                msg += both_password_error + '\n';
            }
        }

        if (msg.length > 0) {
            alert(msg);
            return false;
        } else {
            return true;
        }
    }

    function checkinfo() {
        var nickname = $('#nickname').val();
        var email = $('#email_ep').val();
        if (nickname == '') {
            alert("昵稱不能為空");
            return false;
        }

        if (!checkEmail(email)) {
            alert("郵箱格式不正確");
            return false;
        }
        return true;
    }

    function checkMobileForm() {
        var mobile = $('#mobile_ep').val();
        var mobile_code = $('#mobile_code').val();
        if (!checkMobile(mobile)) {
            alert("手機格式不正確");
            return false;
        }
        if (mobile_code == '') {
            alert("請填寫手機驗證碼");
            return false;
        }
        if (!mobile_flag) {
            alert("請先獲取手機驗證碼");
            return false;
        }
        return true;
    }


    var mobile_flag = false;
    //發送驗證碼
    function sendcode(o) {
        var mobile = $('#mobile_ep').val();
        if (!checkMobile(mobile)) {
            alert("手機格式不正確");
        } else {
            $.ajax({
                url: '/index.php?m=Mobile&c=User&a=send_validate_code&t=' + Math.random(),
                type: 'post',
                dataType: 'json',
                data: {type: $(o).attr('rel'), send: $.trim($('#mobile_ep').val())},
                success: function (res) {
                    if (res.status == 1) {
                        mobile_flag = true;
                        countdown(o);
                    } else {
                        mobile_flag = false;
                        layer.open({content: res.msg, time: 2});
                    }
                }
            });
        }
    }

    var wait = 150;
    function countdown(obj, msg) {
        obj = $(obj);
        if (wait == 0) {
            obj.removeAttr("disabled");
            obj.val(msg);
            wait = 150;
        } else {
            if (msg == undefined || msg == null) {
                msg = obj.val();
            }
            obj.attr("disabled", "disabled");
            obj.val(wait + "秒後重新獲取");
            wait--;
            setTimeout(function () {
                countdown(obj, msg)
            }, 1000)
        }
    }
</script>

<include file="Public/footer_nav"/><body>
</body>
</html>